#!/bin/sh
clear
stop(){
read -p "" STOP
}
while true
do
	echo "欢迎使用cpptide 版本：1.10"
	echo "接下来要做什么？"
	echo "[1]创建/编辑一个项目"
        echo "[2]编译一个项目"
        echo "[3]运行一个项目"
        echo "[4]编译并运行一个项目"
	echo "[5]删除一个项目"
	echo "[6]重命名一个项目"
	echo "[7]从文件复制一个项目"
	echo "[8]在一个项目中创建/编辑/查看一个文件"
	echo "[9]更改编辑器设置"
	echo "[10]查看帮助"
	echo "[11]查看项目列表"
	echo "[12]查看项目内容"
	echo "[13]调试一个项目"
	echo "[14]编译并运行一个文件"
	echo "[15]在一个项目中创建一个文件夹"
	echo "[16]打开一个项目"
	echo "[17]运行一个命令"
        echo "[18]退出cpptide"
	read -p "请输入选项：" CHOOSE
	if [ "$CHOOSE" == "1" ]; then
		read -p "请输入项目名：" PROJECT1
		./edit $PROJECT1
		clear
	elif [ "$CHOOSE" == "2" ]; then
		read -p "请输入项目名：" PROJECT2
		g++ -o ./project/$PROJECT2/$PROJECT2 ./project/$PROJECT2/$PROJECT2.cpp
		clear
        elif [ "$CHOOSE" == "3" ]; then
                read -p "请输入项目名：" PROJECT3
		clear
		./project/$PROJECT3/$PROJECT3
		stop
		clear
        elif [ "$CHOOSE" == "4" ]; then
                read -p "请输入项目名：" PROJECT4
		./build_run ./project/$PROJECT4 $PROJECT4.cpp
		stop
		clear
        elif [ "$CHOOSE" == "5" ]; then
                read -p "请输入项目名：" PROJECT5
		#rmdir ./project/$PROJECT5
		rm -rf ./project/$PROJECT5
		clear
	elif [ "$CHOOSE" == "6" ]; then
		read -p "请输入旧项目名：" PROJECT61
		read -p "请输入新项目名：" PROJECT62
		mv ./project/$PROJECT61 ./project/$PROJECT62
		mv ./project/$PROJECT62/$PROJECT61.cpp ./project/$PROJECT62/$PROJECT62.cpp
		clear
	elif [ "$CHOOSE" == "7" ]; then
		read -p "请输入项目名：" PROJECT71
		#read -p "请输入文件名：" PROJECT73
		read -p "请输入文件位置：" PROJECT72
		if [ ! -d "project/" ]; then
			mkdir project
		fi
		mkdir project/$PROJECT71
		cp $PROJECT72 project/$PROJECT71/$PROJECT71.cpp
		clear
	elif [ "$CHOOSE" == "8" ]; then
		read -p "请输入项目名：" PROJECT81
		read -p "请输入文件名：" PROJECT82
		vim project/$PROJECT81/$PROJECT82
		clear
        elif [ "$CHOOSE" == "9" ]; then
                vim ~/.vimrc
		clear
	elif [ "$CHOOSE" == "10" ]; then
		vim -R helpfile
		clear
	elif [ "$CHOOSE" == "11" ]; then
		ls project
		stop
		clear
	elif [ "$CHOOSE" == "12" ]; then
		read -p "请输入项目名：" PROJECT12
		ls project/$PROJECT12
		stop
		clear
	elif [ "$CHOOSE" == "13" ]; then
		read -p "请输入项目名：" PROJECT13
		g++ -g -o ./project/$PROJECT13/$PROJECT13 ./project/$PROJECT13/$PROJECT13.cpp
		clear
		sudo gdb ./project/$PROJECT13/$PROJECT13
		clear
	elif [ "$CHOOSE" == "14" ]; then
		read -p "请输入项目名：" PROJECT141
		read -p "请输入文件名：" PROJECT142
                ./build_run ./project/$PROJECT141 $PROJECT142.cpp
                clear
	elif [ "$CHOOSE" == "15" ]; then
		read -p "请输入项目名：" PROJECT151
		read -p "请输入文件夹名：" PROJECT152
		if [ ! -d "project/" ]; then
                        mkdir project
                fi
		mkdir project/$PROJECT151/$PROJECT152
		clear
	elif [ "$CHOOSE" == "16" ]; then
		read -p "请输入项目名：" PROJECT16
		open project/$PROJECT16
		clear
	elif [ "$CHOOSE" == "17" ]; then
		read -p "请输入命令：" PROJECT17
		clear
		$PROJECT17
		stop
		clear
	elif [ "$CHOOSE" == "18" ]; then
		read -p "你确定要退出吗？" EXIT
		if [[ "$EXIT" == "y" || "$EXIT" == "Y" ]]; then
			clear
			exit
		elif [[ "$EXIT" == "n" || "$EXIT" == "N" ]]; then
			clear
		else
			clear
		fi
	else
		clear
	fi
done
